package com.spzx.order.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.order.api.domain.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.spzx.order.mapper.OrderLogMapper;
import com.spzx.order.domain.OrderLog;
import com.spzx.order.service.IOrderLogService;

/**
 * 订单操作日志记录Service业务层处理
 *
 * @author atguigu
 * @date 2024-07-12
 */
@Service
public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OrderLog> implements IOrderLogService
{
    @Autowired
    private OrderLogMapper orderLogMapper;
    //异步执行
    @Async
    @Override
    public void saveLogAsync(OrderInfo orderInfo) {
        OrderLog orderLog = new OrderLog();
        orderLog.setOrderId(orderInfo.getId());
        orderLog.setOperateUser(SecurityUtils.getUsername());
        orderLog.setProcessStatus(orderInfo.getOrderStatus());
        orderLog.setNote("提交订单");
        this.save(orderLog);
    }
    @Async
    @Override
    public void updateStatusAsync(String orderId, int status) {
        this.update(Wrappers.lambdaUpdate(OrderLog.class)
                .eq(OrderLog::getOrderId , orderId)
                .set(OrderLog::getProcessStatus , status));

    }
}
